<?php

if (!defined("JOYEASY"))
    exit("Access Denied");

class AvatarAction extends BaseAction {

    public function index() {

        if ($_POST['dosubmit']) {

            $_POST['id'] = $this->_userid;
            if (!$this->dao->create($_POST)) {
                $this->error($this->dao->getError());
            }
            $this->dao->update_time = time();
            $this->dao->last_ip = get_client_ip();
            $result = $this->dao->save();
            if (false !== $result) {
                if ($_POST['aid']) {
                    $Attachment = M('Attachment');
                    $aids = implode(',', $_POST['aid']);
                    $data['userid'] = $this->_userid;
                    $data['catid'] = 0;
                    $data['status'] = '1';
                    $Attachment->where("aid in (" . $aids . ")")->save($data);
                }

                $this->success(L('do_success'));
            } else {
                $this->error(L('do_error'));
            }
            exit;
        }

        $joyeasy_auth_key = sysmd5(C('ADMIN_ACCESS') . $_SERVER['HTTP_USER_AGENT']);
        $joyeasy_auth = authcode('0-1-0-1-jpeg,jpg,png,gif-3-0', 'ENCODE', $joyeasy_auth_key);
        $this->assign('joyeasy_auth', $joyeasy_auth);
        $this->display();
    }

}

?>